package cn.liyicun.cp.cpweb.mapper.ext;

import cn.liyicun.cp.cpweb.entity.ExpectInfo;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.io.Serializable;
import java.util.List;

@Mapper
public interface ExtExpectInfoMapper extends Serializable {

    @Update({
            "update expect_info set open_status=1 ,update_time=now() where end_time<now() and open_status=0"
    })
    int updateByclose();


    @Select({"select * from  expect_info i where i.end_time>now() ORDER by expect limit 1"})
    @Results({
            @Result(column="expect", property="expect", jdbcType=JdbcType.BIGINT, id=true),
            @Result(column="end_time", property="endTime", jdbcType=JdbcType.TIMESTAMP),
    })
    //下一期
    ExpectInfo  nextExpect();


    @Select({"select * from  expect_info i where i.end_time<=now() ORDER by expect desc limit #{limit}"})
    @Results({
            @Result(column="code", property="code", jdbcType=JdbcType.VARCHAR, id=true),
            @Result(column="expect", property="expect", jdbcType=JdbcType.BIGINT, id=true),
            @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="end_time", property="endTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="open_code", property="openCode", jdbcType=JdbcType.VARCHAR),
            @Result(column="open_time", property="openTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="open_status", property="openStatus", jdbcType=JdbcType.INTEGER),
            @Result(column="update_time", property="updateTime", jdbcType=JdbcType.TIMESTAMP)
    })
    //最近10期
    List<ExpectInfo> listLatelyExpect(@Param("limit") int limit );
}